<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
		<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" ></script>
	</head>
	<body>
	<script  th:inline="javascript" type="text/javascript">
	/*<![CDATA[*/
	
		var success = '[[${success}]]';
		var message = [[${message}]];
		var voteId = [[${voteid}]];
		var itemId = [[${itemid}]];
		var votehtml = [[${votehtml}]];
		var templateid=[[${templateid}]];
		var id = '[[${id}]]';
		var code = [[${code}]];
		var sign = JSON.parse([[${sign}]]); //由JSON字符串转换为JSON对象
		var weixinauthorizeurl =[[${weixinauthorizeurl}]];		
		console.log(sign);
	    $(function(){
			if(success){
				//var wechatPay = new WechatPay();
				//wechatPay.pay();
				beforePay();
			}
	    	else{
	    		alert(message);
	    	}
	    });

	    function beforePay(){
	    	if (typeof(WeixinJSBridge) == "undefined"){
	    		if(document.addEventListener){
	    			document.addEventListener('WeixinJSBridgeReady', onPayReady, false);
	    		}
	    		else if (document.attachEvent){
	    			document.attachEvent('WeixinJSBridgeReady', onPayReady); 
	    			document.attachEvent('onWeixinJSBridgeReady', onPayReady);
	    		}
	    	}
	    	else{
	    		onPayReady();
	    	}
	    }
	    function onPayReady(){
	    	WeixinJSBridge.invoke('getBrandWCPayRequest',
	    		sign,
				function(res){      
					if(res.err_msg == "get_brand_wcpay_request:ok" ) {
		    			alert("支付成功！");
		    		}else if(res.err_msg == "get_brand_wcpay_request:fail"){
		    			alert("支付失败！");
		    		}else{  
		    			alert("取消支付！");
		    		}  
	    			window.location.href = weixinauthorizeurl;
	    		}
			);
	    }
		/*]]>*/
		</script>
	</body>
</html>
